
********************************************************************************************************************************
						
														***Marlene Mauk, Max Groemping***
			***Online Disinformation Predicts Inaccurate Beliefs about Election Fairness among Winners and Losers***
													***Replication File  ##6 - MAIN ANALYSES***
						
********************************************************************************************************************************

* create Figure 1
use mergeddata.dta
collapse (firstnm) iso (mean) pef01 pei01 cowcode, by(elecow)
gen position=9
replace position=6 if iso=="BLR" | iso =="BIH" | iso =="PAK" | iso =="PER" | iso =="HRV" | iso =="LTU" | iso =="CHL" | iso =="CHE" | iso =="KGZ" | iso =="SVN"
replace position=12 if iso=="SWE" | iso =="BGD" | iso =="GEO" | iso =="VNM" | iso =="DEU" | iso =="ARM"
replace position=3 if iso =="ISL" | iso =="ARG" | iso =="AZE" | iso =="ECU" | iso =="LBN" | iso =="LTU" | iso =="GRC" | iso =="CZE" | iso =="FIN" | iso =="NZL"
replace position=2 if iso=="DNK" | iso =="NOR" | iso =="FRA"
replace position=5 if iso=="CYP" | iso =="BOL"
replace position=10 if iso=="ESP"
twoway lfitci pef01 pei01, lcolor(black) lpattern(dash) ciplot(rarea) fintensity(50) alcolor(gs14) alpattern(solid) || scatter pef01 pei01, graphregion(color(white)) xtitle("de facto electoral integrity") ytitle("public perceptions of electoral fairness") mstyle(p5) mcolor(black) mlabcolor(black) mlabgap(0.4) mlabvposition(position) msize(small) msymbol(plus) mlabel(iso) mlabsize(vsmall) legend(off)
graph export .\figures\figure1.png, replace
pwcorr pei01 pef01, sig obs
clear


*import count data disinfo01 for histogram overlays
import delimited v1 pef1 pef2 pef6 pef7 pef8 polint satdem soctrust income age edu_2 edu_3 winner pei01 disinfo01 gdpgrowth internet v2eltrnout v2elaccept intmonrestr v2xme_altinf dommonrestr interact elecow using ".\mplus\savedata.dat", delimiter(space, collapse) varnames(nonames)
destring _all, force replace
collapse disinfo01, by(elecow)
save disinfo_counts.dta, replace


* create Figure 2
graph set window fontface "Times New Roman"
clear all
import delimited xaxis pei1 pei1_low pei1_high using ".\mplus\model2.dat", delimiter(tab, collapse) varnames(nonames) 
destring xaxis pei1 pei1_low pei1_high, force replace
append using disinfo_counts.dta
twoway ///
(hist disinfo01, width(0.05) freq start(0.0) color(gs15) yaxis(2)) ///
(pci 0 0 0 1, lc(cranberry)) ///
(line pei1 xaxis, lp(solid) lc(gs1)) ///
(line pei1_low xaxis, lp(dash) lc(gs6)) ///
(line pei1_high xaxis, lp(dash) lc(gs6)), ///
yline(0) ///
graphregion(color(white)) legend(region(lp(blank))) ///
ytitle("effects of electoral integrity on perceptions of fairness") yline(0) ///
xtitle("online disinformation") xlabel(0(0.1)1) ///
legend(off)
graph export .\figures\figure2.png, replace

* create Figure 3
clear all
import delimited xaxis pei1 pei1_low pei1_high using ".\mplus\model3.dat", delimiter(tab, collapse) varnames(nonames) 
destring xaxis pei1 pei1_low pei1_high, force replace
append using disinfo_counts.dta
twoway ///
(hist disinfo01, width(0.05) freq start(0.0) color(gs15) yaxis(2)) ///
(pci 0 0 0 1, lc(cranberry)) ///
(line pei1 xaxis, lp(solid) lc(gs1)) ///
(line pei1_low xaxis, lp(dash) lc(gs6)) ///
(line pei1_high xaxis, lp(dash) lc(gs6)), ///
graphregion(color(white)) legend(region(lp(blank))) ///
ytitle("effects of winner status on perceptions of fairness") yline(0) ///
xtitle("online disinformation") xlabel(0(0.1)1) ///
legend(off)
graph export .\figures\figure3.png, replace

* create Figure 4
clear all
import delimited xaxis pei1 pei1_low pei1_high using ".\mplus\model4_winners.dat", delimiter(tab, collapse) varnames(nonames) 
destring xaxis pei1 pei1_low pei1_high, force replace
save model4_high.dta, replace
clear
import delimited xaxis pei1alt pei1alt_low pei1alt_high using ".\mplus\model4_losers.dat", delimiter(tab, collapse) varnames(nonames) 
destring xaxis pei1alt pei1alt_low pei1alt_high, force replace
gen yline = 0
save model4_low.dta, replace
append using model4_high.dta
append using disinfo_counts.dta
twoway ///
(hist disinfo01, width(0.05) freq start(0.0) color(gs15) yaxis(2)) ///
(pci 0 0 0 1, lc(cranberry)) ///
(line yline xaxis, lp(solid) lc(cranberry) lwidth(0.1)) ///
(line pei1 xaxis, lp(solid) lc(black)) ///
(line pei1_high xaxis, lp(solid) lc(black) lwidth(0.1)) ///
(line pei1_low xaxis, lp(solid) lc(black) lwidth(0.1)) ///
(line pei1alt_high xaxis, lp(dash) lc(gs9) lwidth(0.1)) ///
(line pei1alt_low xaxis, lp(dash) lc(gs9) lwidth(0.1)) ///
(line pei1alt xaxis, lp(dash) lc(gs9)), ///
graphregion(color(white)) legend(region(lp(blank))) ///
ytitle("effects of electoral integrity on public perceptions of fairness") yline(0) ///
xtitle("online disinformation, for winners (solid line) and losers (dashed line)") xlabel(0(0.1)1) ///
legend(off)
graph export .\figures\figure4.png, replace
clear